//
//  huiyuanDetailsViewController.m
//  daogouApp
//
//  Created by panquanReabam.com on 15-6-2.
//  Copyright (c) 2015年 jiezsoft.com. All rights reserved.
//

#import "DeliveryConfirmTheOrderViewController.h"
#import "HttpRequest.h"
#import "JSONKit.h"
#import "OptionNameListViewController.h"
#import "UIViewExt.h"
#import "RDVTabBarController.h"
#import "MJRefresh.h"
#import "CommonDetailView.h"
#import "DeliveryDetailModel.h"
#import "UIButton+WebCache.h"
#import "AttributedLabel.h"
#import "MembershipDetailsViewController.h"
#import "DeliverylistViewController.h"
#import "huiyuanDetailsCell.h"
#import "OrderDetailM.h"
@interface DeliveryConfirmTheOrderViewController ()<MBProgressHUDDelegate,UIGestureRecognizerDelegate,UINavigationControllerDelegate,UITextFieldDelegate,UITextViewDelegate,OptionNameListViewControllerDelegate>
@property(nonatomic,strong)NSString*sats;
@property (strong, nonatomic) NSString*GuideCode;

@end
@implementation DeliveryConfirmTheOrderViewController
{
    CommonDetailView*CommonView;
    UIScrollView*mainScroll;
    UIButton*tureBtn;
    UITextField*xianjinTextFied;
    UITextField*fuwuTextFied;
    NSMutableArray *orderItemIds;
    NSMutableArray *selectshuliangArray;
    UITableView*table;
    NSMutableArray*mItemsArray;
    NSMutableArray*ModelArray;
    NSMutableArray*quantityArray;

}
@synthesize alt = alt;
-(void)BackAction:(UIButton *)sender{
    
    
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)viewDidDisappear:(BOOL)animated

{
    [super viewDidDisappear:animated];
    self.navigationController.delegate = nil;
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self add];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [[self rdv_tabBarController] setTabBarHidden:YES];
    self.navigationController.navigationBar.barStyle = UIBaselineAdjustmentNone;
    UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 43,ScreenWidth, 1)];
    [lineLabel setBackgroundColor:[UIColor colorWithRed:238.0/255.0 green:238.0/255.0 blue:238.0/255.0 alpha:1.0]];
    [self.navigationController.navigationBar addSubview:lineLabel];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setBarTintColor:Color];
    
    UIImage* backImage = [UIImage imageNamed:@"fanhui"];
    CGRect backframe = CGRectMake(0,0,30,30);
    UIButton* backButton= [[UIButton alloc] initWithFrame:backframe];
    [backButton setBackgroundImage:backImage forState:UIControlStateNormal];
    backButton.titleLabel.font=[UIFont systemFontOfSize:13];
    [backButton addTarget:self action:@selector(BackAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    self.navigationController.delegate = self;
    
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
    if ( [self.sat isEqualToString:@"订单详情确认提货"]) {
         self.title=@"提货确认";
    }else{
        self.title=@"配送确认";
    
    }
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                     [UIColor blackColor],
                                                                     UITextAttributeTextColor,
                                                                     [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1],
                                                                     UITextAttributeTextShadowColor,
                                                                     [NSValue valueWithUIOffset:UIOffsetMake(0, 0)],
                                                                     UITextAttributeTextShadowOffset,
                                                                     [UIFont fontWithName:@"Helvetica Neue" size:tetlefot],
                                                                     UITextAttributeFont,nil]];

    
    
    
    
    
}
- (void)NeedOrderType:(NSString *)NeedOrderType NeedOrderCode:(NSString *)NeedOrderCode{}
- (void)WhsInType:(NSString *)WhsInType WhsInTypeCode:(NSString *)WhsInTypeCode{}
- (void)ServiceType:(NSString *)ServiceType ServiceTypeCode:(NSString *)ServiceTypeCode{}
- (void)ReasonType:(NSString *)ReasonType ReasonTypeCode:(NSString *)ReasonTypeCode{}
- (void)ExpressCompany:(NSString *)ExpressCompany ExpressCompanyCode:(NSString *)ExpressCompanyCode{
    fuwuTextFied.text=ExpressCompany;
}
-(void)add{

    
    UIView*view1=[[UIView alloc]initWithFrame:CGRectMake(0, 64, ScreenWidth, 80/2)];
    view1.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:view1];
    
    UIView*gayView1=[[UIView alloc]initWithFrame:CGRectMake(0, view1.bottom, ScreenWidth, 10)];
    gayView1.backgroundColor=zuiqianhuiColor;
    gayView1.layer.borderWidth = 0.40;
    gayView1.layer.borderColor = qianhuiColor.CGColor;
    [self.view addSubview:gayView1];
    UILabel* duogou=[[UILabel alloc]initWithFrame:CGRectMake(15, 0, 40, 40)];
    duogou.text=[NSString stringWithFormat:@"员工"];
    duogou.textColor=shenhuiColor;
    duogou.font=[UIFont systemFontOfSize:contenfot];
    [view1 addSubview:duogou];
    NSUserDefaults *user1 = [NSUserDefaults standardUserDefaults];
    NSString* UserName = [user1 objectForKey:@"userName"];
    UIButton*staffNameBtn=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth-300,  0,260,40)];
    [staffNameBtn setTitle:UserName forState:UIControlStateNormal];
    staffNameBtn.titleLabel.font=[UIFont systemFontOfSize:contenfot];
    staffNameBtn.titleLabel.textAlignment=NSTextAlignmentRight;
    //    [staffNameBtn addTarget:self action:@selector(chooseUserBtn:) forControlEvents:UIControlEventTouchUpInside];
    staffNameBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
    [staffNameBtn setTitleColor:qianheiColor forState:UIControlStateNormal];
    [view1 addSubview:staffNameBtn];
    UIButton*chooseUserBtn = [[UIButton alloc]init];
    chooseUserBtn.frame = CGRectMake(ScreenWidth-40,5.5, 30, 30);
    //    [chooseUserBtn addTarget:self action:@selector(chooseUserBtn:) forControlEvents:UIControlEventTouchUpInside];
    [chooseUserBtn setImage:[UIImage imageNamed:@"shouqi"] forState:UIControlStateNormal];
    [view1 addSubview:chooseUserBtn];
    table = [[UITableView alloc]initWithFrame:CGRectMake(0, 64+40+10, ScreenWidth, ScreenHeight-64-40-10) style:UITableViewStylePlain];
    table.delegate = self;
    table.dataSource = self;
    table.separatorStyle=UITableViewCellSeparatorStyleNone;
    [self.view addSubview:table];
    quantityArray=[[NSMutableArray alloc] init];
    orderItemIds=[[NSMutableArray alloc] init];
   NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setValue:Token forKey:@"tokenId"];
    [param setValue:self.orderId forKey:@"orderId"];
    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
    [HttpRequest requestData:@"Business/Order/Detail" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
           NSLog(@"-----------%@", severDataDict.dataDict);
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                CommonView = [[CommonDetailView alloc]init];
                DeliveryDetailModel*dataModel=[DeliveryDetailModel dataModelWithDeliveryDetailDict:severDataDict.dataDict];
                CommonView.DeliveryModel=dataModel;
                CommonView.frame=CGRectMake(0, 0, ScreenWidth, CommonView.heightView.bottom);
                table.tableHeaderView=CommonView;
                
                mItemsArray =[[NSMutableArray alloc]init];
                ModelArray=[[NSMutableArray alloc]init];
                
                
                
                mItemsArray=[NSMutableArray arrayWithArray:[severDataDict.dataDict objectForKey:@"orderItem"]];
                
                if (mItemsArray.count>0) {
                    for (NSDictionary *dic in mItemsArray) {
                        NSString*quantity1=[dic valueForKey:@"quantity"];
                         NSString*deliveryQuantity1=[dic valueForKey:@"deliveryQuantity"];
                       
                        
                        if (quantity1.intValue-deliveryQuantity1.intValue==0) {
                            
                        }else{
                        [quantityArray addObject:[NSString stringWithFormat:@"%d",quantity1.intValue-deliveryQuantity1.intValue]];
                        [orderItemIds addObject:[dic valueForKey:@"id"]];
                        OrderDetailM *dataModel=[OrderDetailM mj_objectWithKeyValues:dic];
                        [ModelArray addObject:dataModel];
                        }
                    }
                    
                }
                [table reloadData];

                
               
                UIView*footview=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 300)];
                footview.backgroundColor=zuiqianhuiColor;
                table.tableFooterView=footview;
                UILabel*line=[[UILabel alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 0.25)];
                line.backgroundColor=qianhuiColor;
               [footview addSubview:line];
                UIView*noteAddTagView=[[UIView alloc]initWithFrame:CGRectMake(0, 10, ScreenWidth, 75)];
                noteAddTagView.backgroundColor=[UIColor whiteColor];
                noteAddTagView.layer.borderColor = qianhuiColor.CGColor;
                [noteAddTagView.layer setBorderWidth:0.40];   //边
                [footview addSubview:noteAddTagView];
                
                UILabel*note=[[UILabel alloc]initWithFrame:CGRectMake(15, 0, ScreenWidth, 45)];
                note.text=@"备注";
                note.textColor=qianheiColor;
                note.font= [UIFont systemFontOfSize:14];
                [noteAddTagView addSubview:note];
                UILabel*noteLabel=[[UILabel alloc]initWithFrame:CGRectMake(15, 25, 150, 50)];
                noteLabel.font= [UIFont systemFontOfSize:14];
                noteLabel.textColor=shenhuiColor;
                noteLabel.numberOfLines=0;
                if ([[NSString stringWithFormat:@"%@",  [[severDataDict.dataDict objectForKey:@"order"]objectForKey:@"remark"]]isEqualToString:@""]) {
                    noteLabel.text=@"无";
                }else{
                    noteLabel.text=[NSString stringWithFormat:@"%@",  [[severDataDict.dataDict objectForKey:@"order"]objectForKey:@"remark"]];
                }
                [noteAddTagView addSubview:noteLabel];
               
                if ( [self.sat isEqualToString:@"订单详情确认提货"]) {
                    
                
                }else{
                                       
                
                UIView*fuwuView=[[UIView alloc]initWithFrame:CGRectMake(0, noteAddTagView.bottom+10, ScreenWidth, 100)];
                fuwuView.backgroundColor=[UIColor whiteColor];
                fuwuView.layer.borderColor = qianhuiColor.CGColor;
                [fuwuView.layer setBorderWidth:0.40];   //边
                [footview addSubview:fuwuView];
                UILabel* leixin=[[UILabel alloc]initWithFrame:CGRectMake(15, 0, 70, 50)];
                leixin.text=[NSString stringWithFormat:@"物流商"];
                leixin.textColor=shenhuiColor;
                leixin.font=[UIFont systemFontOfSize:14];
                [fuwuView addSubview:leixin];
                
                fuwuTextFied=[[UITextField alloc]initWithFrame:CGRectMake(leixin.right,0, ScreenWidth*300/750,50)];
                fuwuTextFied.borderStyle = UITextBorderStyleNone;
                fuwuTextFied.keyboardType = UIKeyboardTypeDecimalPad;
                fuwuTextFied.font = [UIFont systemFontOfSize: 14];
                fuwuTextFied.textColor=qianheiColor;
                fuwuTextFied.autocapitalizationType = UITextAutocapitalizationTypeSentences;
                fuwuTextFied.tag=6;
                fuwuTextFied.placeholder = @"请选择物流商"; //默认显示的字
                fuwuTextFied.delegate = self;
                [fuwuTextFied setUserInteractionEnabled:NO];
                fuwuTextFied.clearButtonMode = UITextFieldViewModeWhileEditing;
                [fuwuView addSubview:fuwuTextFied];
                UIButton*jiant = [[UIButton alloc] initWithFrame:CGRectMake(90,0,ScreenWidth, 50)];
                [jiant addTarget:self action:@selector(xuanzhidaogou:) forControlEvents:UIControlEventTouchUpInside];
                [fuwuView addSubview:jiant];
                UIButton*jiantouBtn12 = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-40,8,33, 33)];
                [jiantouBtn12 setImage:[UIImage imageNamed:@"shouqi"] forState:UIControlStateNormal];
                [jiantouBtn12 addTarget:self action:@selector(xuanzhidaogou:) forControlEvents:UIControlEventTouchUpInside];
                [fuwuView addSubview:jiantouBtn12];

                UILabel *lineLabel11=[[UILabel alloc] initWithFrame:CGRectMake(10, 50, ScreenWidth-20, 0.40)];
                lineLabel11.backgroundColor=qianhuiColor;
                [fuwuView addSubview:lineLabel11];
              
                
                UILabel* jine=[[UILabel alloc]initWithFrame:CGRectMake(15, lineLabel11.bottom, 70, 50)];
                jine.text=[NSString stringWithFormat:@"物流单号"];
                jine.textColor=shenhuiColor;
                jine.font=[UIFont systemFontOfSize:14];
                [fuwuView addSubview:jine];
                
                xianjinTextFied=[[UITextField alloc]initWithFrame:CGRectMake(jine.right,lineLabel11.bottom, ScreenWidth-105,50)];
                xianjinTextFied.borderStyle = UITextBorderStyleNone;
                xianjinTextFied.keyboardType = UIKeyboardTypeDecimalPad;
                xianjinTextFied.font = [UIFont systemFontOfSize: 14];
                xianjinTextFied.textColor=qianheiColor;
                xianjinTextFied.autocapitalizationType = UITextAutocapitalizationTypeSentences;
                xianjinTextFied.tag=6;
                xianjinTextFied.placeholder = @"请输入物流单号"; //默认显示的字
                xianjinTextFied.delegate = self;
                [xianjinTextFied setUserInteractionEnabled:YES];
                xianjinTextFied.clearButtonMode = UITextFieldViewModeWhileEditing;
                [fuwuView addSubview:xianjinTextFied];
                
                
                
                UIView* myToolBar=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, viewheight)];
                myToolBar.backgroundColor=jianpancolor;
                UIButton*  tubtnDone=[[UIButton alloc]initWithFrame:CGRectMake(logoX,logoY, logoheight, logowidth)];
                [tubtnDone setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
                [tubtnDone addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
                [myToolBar addSubview:tubtnDone];
                UIButton*btnDone111=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width - 55, 12, 40, 16)];
                [btnDone111 setTitle:@"确定" forState:UIControlStateNormal];
                [btnDone111 setTitleColor:jianpancolor1 forState:UIControlStateNormal];
                btnDone111 .titleLabel .font=[UIFont systemFontOfSize:keyboardFot];
                [btnDone111 addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
                [myToolBar addSubview:btnDone111];
                myToolBar.alpha=alp;
                UIButton* dabtn=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width-60, 0, 60, 40)];
                [dabtn addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
                [myToolBar addSubview:dabtn];
                
                
                
                
                xianjinTextFied.inputAccessoryView = myToolBar;
                [mainScroll setContentSize:CGSizeMake(ScreenWidth, footview.bottom+150)];
                    
                }
                
                tureBtn=[[UIButton alloc]initWithFrame:CGRectMake(0, ScreenHeight-48, ScreenWidth, 48)];
                if ( [self.sat isEqualToString:@"订单详情确认提货"]) {
                    [tureBtn setTitle:@"提货确认" forState:UIControlStateNormal];
                }else{
                    [tureBtn setTitle:@"配送确认" forState:UIControlStateNormal];
                    
                }

               
                tureBtn.backgroundColor=luseColor;
                [tureBtn addTarget:self action:@selector(queren:) forControlEvents:UIControlEventTouchUpInside];
                tureBtn.titleLabel.font=[UIFont systemFontOfSize:titleNamefot];
                [tureBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                [self.view addSubview:tureBtn];
                }else{
                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                [Global showTextHudSub:requestResultStr view:self.view];
            }
            
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            [Global showTextHudSub:severDataDict.resultStr view:self.view];
        }
        
    }];
    }




#pragma mark - Table view data source
#pragma mark - Table view delegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [ModelArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

       static NSString *CellIdentifier = @"Cell";
    
    huiyuanDetailsCell* cell = (huiyuanDetailsCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        NSArray* nib = [[NSBundle mainBundle] loadNibNamed:@"huiyuanDetailsCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }

    
    if (cell==nil) {
        
    }else{
        while ([cell.contentView.subviews lastObject] != nil) {
            [(UIView*)[cell.contentView.subviews lastObject] removeFromSuperview];  //删除并进行重新分配
        }
    }

    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    OrderDetailM *dataModel=ModelArray[indexPath.row];
    

        UIView*goodsView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 120)];
        
        UIImageView*headImageFull = [[UIImageView alloc]init];
        [headImageFull.layer setCornerRadius:4.0];
        [headImageFull.layer setBorderWidth:0.5];
        [headImageFull.layer setMasksToBounds:YES];
        [headImageFull setImageWithURL:[NSURL URLWithString:  dataModel.headImageFull] placeholderImage:[UIImage imageNamed:@"zhengfangxing"]];
        CGColorSpaceRef colorSpace2 = CGColorSpaceCreateDeviceRGB();
        CGColorRef colorref2 = CGColorCreate(colorSpace2,(CGFloat[]){ 0.93, 0.93, 0.93, 0.93 });
        [headImageFull.layer setBorderColor:colorref2];//边框颜色
        headImageFull.frame = CGRectMake(15, 17.5, 82, 82);
        [goodsView addSubview:headImageFull];
        
        
        NSString *s2 =[NSString stringWithFormat:@"%@", dataModel.itemName];
        UIFont *font1 = [UIFont systemFontOfSize:14];
        CGSize size1 = CGSizeMake(ScreenWidth-82-15-30, 2000);
        CGSize labelsize1 = [s2 sizeWithFont:font1 constrainedToSize:size1 lineBreakMode:NSLineBreakByCharWrapping];
        UILabel*itemName = [[UILabel alloc]init];
        itemName.numberOfLines=0;
        itemName.text=s2;
        itemName.frame = CGRectMake( headImageFull.right+10, 17.5, ScreenWidth-82-15-30, labelsize1.height);
        itemName.textColor=qianheiColor;
        itemName.font=[UIFont systemFontOfSize:14];
        [goodsView addSubview:itemName];
        
        
        UILabel*itemType = [[UILabel alloc]init];
        itemType.frame = CGRectMake( headImageFull.right+10, 68, ScreenWidth-120, 13);
        itemType.font=[UIFont systemFontOfSize:12];
        itemType.textColor=shenhuiColor;
        itemType.text=[NSString stringWithFormat:@"%@",dataModel.specName];
        [goodsView addSubview:itemType];
    
    
    
        NSString *quantitStr =[NSString stringWithFormat:@"数量 %@",dataModel.quantity];
        UIFont *quantitStrfont1 = [UIFont systemFontOfSize:13];
        CGSize quantitStrsize1 = CGSizeMake(ScreenWidth-82-15-30, 2000);
        CGSize quantitStrlabelsize1 = [quantitStr sizeWithFont:quantitStrfont1 constrainedToSize:quantitStrsize1 lineBreakMode:NSLineBreakByCharWrapping];

        UILabel*quantity = [[UILabel alloc]init];
        quantity.frame = CGRectMake( headImageFull.right+10, 85, quantitStrlabelsize1.width,12);
        quantity.font=[UIFont systemFontOfSize:12];
        quantity.textColor=shenhuiColor;
        quantity.text=[NSString stringWithFormat:@"数量 %@",dataModel.quantity];
        [goodsView addSubview:quantity];
        
        
        UILabel*dealPrice = [[UILabel alloc]init];
        dealPrice.frame = CGRectMake(quantity.right+20, 85, 230,13);
        NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
        [numberFormatter setPositiveFormat:@"###,##0.00;"];
        NSString *formattedNumberString = [numberFormatter stringFromNumber:[NSNumber numberWithDouble:dataModel.dealPrice.doubleValue]];
        dealPrice.text=[NSString stringWithFormat:@"¥ %@",formattedNumberString];
        
        dealPrice.textColor=qianheiColor;
        dealPrice.font=[UIFont systemFontOfSize:13];
        NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"¥ %@" ,formattedNumberString]];
        
        [AttributedStr addAttribute:NSFontAttributeName
         
                              value:[UIFont systemFontOfSize:12]
         
                              range:NSMakeRange(0, 1)];
        
        [AttributedStr addAttribute:NSForegroundColorAttributeName
         
                              value:shenhuiColor
         
                              range:NSMakeRange(0, 1)];
        dealPrice.attributedText = AttributedStr;
        
        [goodsView addSubview:dealPrice];
        UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(10, 275/2-0.40, ScreenWidth-20, 0.40)];
        lineLabel1.backgroundColor=qianhuiColor;
        [goodsView addSubview:lineLabel1];
        
        [cell.contentView addSubview:goodsView];
    
    
    UIView*countParentView=[[UIView alloc] initWithFrame:CGRectMake(ScreenWidth-125, 100, 110, 30)];
    countParentView.layer.borderWidth=1.0;
    countParentView.layer.borderColor=[UIColor colorWithRed:240.0/255.0f green:240.0/255.0f blue:240.0/255.0f alpha:240.0/255.0f].CGColor;
    [cell.contentView addSubview:countParentView];

    cell.time.text=[NSString stringWithFormat:@"%@",  quantityArray[indexPath.row]];
    cell.time.textColor=qianheiColor;
    cell.time.center=countParentView.center;
    cell.time.textAlignment=NSTextAlignmentCenter;
    cell.time.font=[UIFont systemFontOfSize:16];
    [cell.contentView addSubview:cell.time];
    
    UIButton *CountBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    [CountBtn setFrame:CGRectMake(0, 0, 50,30)];
    CountBtn.tag=indexPath.row;
    CountBtn.center=countParentView.center;
    [CountBtn addTarget:self action:@selector(countBtn:) forControlEvents:UIControlEventTouchUpInside];
    [cell.contentView addSubview:CountBtn];
    UIButton*jian=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth-125, 100, 30, 30)];
    jian.tag=indexPath.row;
    [jian setImage:[UIImage imageNamed:@"jian_hui.png"] forState:UIControlStateNormal];
    [jian addTarget:self action:@selector(jian:) forControlEvents:UIControlEventTouchUpInside];
    [cell.contentView addSubview:jian];
    
    UIButton*jia=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth-45,100, 30, 30)];
    jia.tag=indexPath.row;
    [jia setImage:[UIImage imageNamed:@"jia.png"] forState:UIControlStateNormal];
    [jia addTarget:self action:@selector(jia:) forControlEvents:UIControlEventTouchUpInside];
    [cell.contentView addSubview:jia];

    cell.Amount.frame=CGRectMake(headImageFull.right+10, 112, 400*ScreenWidth/750,13);
    if ( [self.sat isEqualToString:@"订单详情确认提货"]) {
        cell.Amount.text=[NSString stringWithFormat:@"已提货数量 %@", dataModel.deliveryQuantity];
    }else{
        cell.Amount.text=[NSString stringWithFormat:@"已配送数量 %@", dataModel.deliveryQuantity];
        
    }
   
    cell.Amount.textColor=luseColor;
    cell.Amount.font=[UIFont systemFontOfSize:12];
    [cell.contentView addSubview:cell.Amount];
    return cell;
}

- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

    
    return  275/2;
}



-(void)countBtn:(UIButton *)sender{
    
    
    UIButton* button=(UIButton * )sender;
    huiyuanDetailsCell* cell=(huiyuanDetailsCell* )button.superview.superview;
    UIAlertView * alertView = [[UIAlertView alloc]initWithTitle:@"数量"
                               
                                                        message:@"请输入修改的数量"
                               
                                                       delegate:self
                               
                                              cancelButtonTitle:@"取消"
                               
                                              otherButtonTitles:@"确定",nil];
    alertView.tag=sender.tag;
    [alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];
    UITextField * text1 = [alertView textFieldAtIndex:0];
    text1.text=cell.time.text;
    text1.contentVerticalAlignment= UIControlContentVerticalAlignmentCenter;
    text1.keyboardType = UIKeyboardTypeNumberPad;
    [alertView show];
}


-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 1)
        {
            UITextField * text1 = [alertView textFieldAtIndex:0];
            text1.contentVerticalAlignment= UIControlContentVerticalAlignmentCenter;
            text1.keyboardType = UIKeyboardTypeNumberPad;
            [quantityArray replaceObjectAtIndex:alertView.tag withObject:text1.text];
            [table reloadData];
            
        }
        
    
}

-(void)jia:(UIButton*)sender{
    OrderDetailM *dataModel=ModelArray[sender.tag];
    UIButton* button=(UIButton * )sender;
    huiyuanDetailsCell* cell=(huiyuanDetailsCell* )button.superview.superview;
   
        int d;
        d= cell.time.text.intValue;
        d++;
    if (d>(dataModel.quantity.intValue-dataModel.deliveryQuantity.intValue)) {
        [self showAlertMessage:@"不能超出商品数量！"];
    }else{
        [quantityArray replaceObjectAtIndex:sender.tag withObject:[NSString stringWithFormat:@"%d", d]];
        cell.time.text=[NSString stringWithFormat:@"%d", d];
    
    }
}
-(void)jian:(UIButton*)sender{
    UIButton* button=(UIButton * )sender;
    huiyuanDetailsCell* cell=(huiyuanDetailsCell* )button.superview.superview;
        int d;
        d= cell.time.text.intValue;
        d--;
        if (d<0) {
            [self showAlertMessage:@"不能小于0！"];
        }else{
        
        [quantityArray replaceObjectAtIndex:sender.tag withObject:[NSString stringWithFormat:@"%d", d]];
        cell.time.text=[NSString stringWithFormat:@"%d", d];
    }
    
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view delegate
-(void)queren:(UIButton*)sender{
   if ( [self.sat isEqualToString:@"订单详情确认提货"]) {
   
       NSString *quantity = [quantityArray valueForKeyPath:@"@sum.floatValue"];
       
       if (quantity.intValue==0) {
           [self showAlertMessage:@"商品数量不能为0！"];
           
       }else{
           
           [self ture];
           
       }

   }else{
        if ([fuwuTextFied.text length] <1)
        {
            [self showAlertMessage:@"请输入物流商名字"];
        }
        else{
            if ([xianjinTextFied.text length] < 1)
            {
                [self showAlertMessage:@"请输入物流商号"];
            }
            else
            {
            
                
             
                
                    NSString *quantity = [quantityArray valueForKeyPath:@"@sum.floatValue"];
                    
                    if (quantity.intValue==0) {
                        [self showAlertMessage:@"商品数量不能为0！"];

                    }else{
                    
                     [self ture];
                    
                }
            
            }
        }
   }
}
-(void)ture{
    
        NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
        NSString* Token = [user objectForKey:@"tokenId"];
        NSMutableDictionary *params = [NSMutableDictionary new];
        [params setValue:Token forKey:@"tokenId"];

        [params setValue:self.orderId forKey:@"orderId"];
        [params setValue:fuwuTextFied.text forKey:@"expressCompany"];
        [params setValue:xianjinTextFied.text forKey:@"expressNumber"];
        [params setValue:@"" forKey:@"courier"];
                
                NSMutableArray *orderItem=[NSMutableArray array];
                for (int i=0; i<quantityArray.count; i++) {
                  
                    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
                    NSString *oItemId = [orderItemIds objectAtIndex:i];
                    NSString *quantity = [quantityArray objectAtIndex:i];
                    if (quantity.intValue==0) {
                        
                    }else{
                    [dic setValue:oItemId forKey:@"oItemId"];
                    [dic setValue:quantity forKey:@"quantity"];
                        [orderItem addObject:dic];
                    
                    }
                }
                
        [params setValue:orderItem  forKey:@"orderItems"];
        [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
        [HttpRequest requestData:@"Business/Order/DeliveryConfirm" params:params success:^(BOOL isSuccess, SeverData *severDataDict) {
            if (isSuccess) {
                
                NSLog(@"%@",severDataDict.dataDict);
                
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                    if ([self.backSat isEqualToString:@"订单列表"]) {
                        NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                        [Global showTextHudSub:requestResultStr view:self.view];
                        DeliverylistViewController *detailViewController = [[DeliverylistViewController alloc] init];
                        [self.navigationController pushViewController:detailViewController animated:YES];
                        
                    }else{
                    [[NSNotificationCenter defaultCenter]postNotificationName:@"orderList" object:nil];
                    [_mDelegate update:@""];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    [Global showTextHudSub:requestResultStr view:self.view];
                    [self.navigationController popViewControllerAnimated:YES];
                    
                    }
                
                }else{
                     [Global hideProgressHUDInternal:self.view];
                    NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                    [Global showTextHudSub:requestResultStr view:self.view];
                }
                
            }
            else
            {
                [Global hideProgressHUDInternal:self.view];
                [Global showTextHudSub:severDataDict.resultStr view:self.view];
            }
            
        }];

   
}
-(void)xuanzhidaogou:(id)sender
{
    
    OptionNameListViewController *detailViewController = [[OptionNameListViewController alloc] init];
    detailViewController.optionName=@"ExpressCompany";
    detailViewController.titlename=@"选择物流商";
    detailViewController.mDelegate=self;
    [self.navigationController pushViewController:detailViewController animated:YES];
    
    
}
-(void)xiangqing:(UIButton*)sender{
    
    
}
- (void)textFieldDidBeginEditing:(UITextField *)textField{
    
    if (textField.tag == 6)
    {
        
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
        table .frame =CGRectMake(0, -200, ScreenWidth, ScreenHeight-54);
        [UIView commitAnimations];
        }
    
}

//回收键盘
-(void)OnTapDone{
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    table .frame =CGRectMake(0, 64+40+10, ScreenWidth, ScreenHeight-64-40-10);
    [UIView commitAnimations];
    
    [xianjinTextFied resignFirstResponder];
 

    
    
}
-(void)closeKeyBoad
{

    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    mainScroll .frame =CGRectMake(0, 0, ScreenWidth, ScreenHeight);
    [UIView commitAnimations];
    
    [xianjinTextFied resignFirstResponder];
    
}
- (void)showAlertWait
{
    alt = [[UIAlertView alloc] initWithTitle:@"网络不稳定 ！" message:@"请确认网络" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
    
}

- (void)showAlertMessage:(NSString *)msg
{
    alt = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
}
- (void)hideAlert
{
    if (alt != nil)
    {
        [alt dismissWithClickedButtonIndex:0 animated:YES];
        alt = nil;
    }
}

@end
